package com.xiaoKe.zhonghzu.global.tool;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.widget.TimePicker;

import com.xiaoKe.zhonghzu.ui.onClick.OnClickListenerPositionObject;

import java.util.Calendar;

/**
 * @ProjectName : xiaoke-pad-zhongzhu
 * @Author : Shijingna
 * @Time : 2024/9/20 09:08
 * @Description : 文件描述
 */
public   class    DatePickerTool {

    private static Calendar calendar = Calendar.getInstance();
    private  static DatePickerDialog datePickerDialog;
    private static TimePickerDialog timePickerDialog;
 //选择时分秒
    public  static  void showDatePickerDialog(Context context, OnClickListenerPositionObject onClickListenerPositionObject) {
        datePickerDialog = new DatePickerDialog(context,
                (android.widget.DatePicker view, int year, int monthOfYear, int dayOfMonth) -> {
                    calendar.set(Calendar.YEAR, year);
                    calendar.set(Calendar.MONTH, monthOfYear);
                    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    showTimePickerDialog(context, new OnClickListenerPositionObject() {
                        @Override
                        public void onItemClick(Object ob) {
                            onClickListenerPositionObject.onItemClick(ob);
                        }
                    });

                },
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH)
        );
        datePickerDialog.show();
    }
 //选择年月日的
    public  static  void showDatePickerMontHDialog(Context context, OnClickListenerPositionObject onClickListenerPositionObject) {
        datePickerDialog = new DatePickerDialog(context,
                (android.widget.DatePicker view, int year, int monthOfYear, int dayOfMonth) -> {
                    calendar.set(Calendar.YEAR, year);
                    calendar.set(Calendar.MONTH, monthOfYear);
                    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                    String dateTime = calendar.get(Calendar.YEAR) + "-" +
                            (calendar.get(Calendar.MONTH) + 1) + "-" +
                            calendar.get(Calendar.DAY_OF_MONTH) ;
                    onClickListenerPositionObject.onItemClick(dateTime);
                },
                calendar.get(Calendar.YEAR),
                calendar.get(Calendar.MONTH),
                calendar.get(Calendar.DAY_OF_MONTH)
        );
        datePickerDialog.show();
    }

    private   static  void showTimePickerDialog(Context context,OnClickListenerPositionObject onClickListenerPositionObject) {
        timePickerDialog = new TimePickerDialog(context,
                (TimePicker view, int hourOfDay, int minute) -> {
                    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    calendar.set(Calendar.MINUTE, minute);
                    // 处理选择的日期和时间
                    String dateTime = calendar.get(Calendar.YEAR) + "-" +
                            (calendar.get(Calendar.MONTH) + 1) + "-" +
                            calendar.get(Calendar.DAY_OF_MONTH) + " " +
                            hourOfDay + ":" +
                            (minute < 10 ? "0" : "") + minute;
                    // 更新 UI 或执行其他操作
                    onClickListenerPositionObject.onItemClick(dateTime);
                },
                calendar.get(Calendar.HOUR_OF_DAY),
                calendar.get(Calendar.MINUTE),
                true // 使用 24 小时制
        );
        timePickerDialog.show();
    }


    public    static  void showTimeHourPickerDialog(Context context,OnClickListenerPositionObject onClickListenerPositionObject) {
        timePickerDialog = new TimePickerDialog(context,
                (TimePicker view, int hourOfDay, int minute) -> {
                    calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
                    calendar.set(Calendar.MINUTE, minute);
                    // 处理选择的日期和时间
                    String dateTime = hourOfDay + ":" +
                            (minute < 10 ? "0" : "") + minute;
                    // 更新 UI 或执行其他操作
                    onClickListenerPositionObject.onItemClick(dateTime);
                },
                calendar.get(Calendar.HOUR_OF_DAY),
                calendar.get(Calendar.MINUTE),
                true // 使用 24 小时制
        );
        timePickerDialog.show();
    }

}
